package org.damazio.flight.checklists;

import org.damazio.flight.checklists.data.CheckListsSchema;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

public class CheckListEdit extends Activity {

  private static final String NEW_LIST_KEY = "new_list";
  private static final String PARENT_ID_KEY = "parent_id";
  private static final String PARENT_NAME_KEY = "parent_name";
  private CheckListsSchema schema;
  private long parentId;
  private String parentName;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    schema = new CheckListsSchema(this);
  }

  @Override
  protected void onDestroy() {
    schema.close();

    super.onDestroy();
  }

  private boolean isInputValid() {
    return true;
  }

  private void saveList() {
    String name = "name";

    // Insert list into database
    long listId = schema.getCheckListsTable().insert(name, parentId);

    // Now show it
    CheckListsMain.showCheckList(this, listId, name, parentName);
  }

  public static void addNewList(Context context, long parentId, String parentName) {
    Intent intent = new Intent(context, CheckListItemEdit.class);
    intent.putExtra(NEW_LIST_KEY, true);
    intent.putExtra(PARENT_ID_KEY, parentId);
    intent.putExtra(PARENT_NAME_KEY, parentName);
    context.startActivity(intent);
  }
}
